package com.sf.guava.collect;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

/**
 * @Classname BimapTest
 * @Description 双向映射Map
 * @Date 2019/12/11 0011 17:24
 * @Created by 埔枘
 */
public class BimapTest {
    public static void main(String args[]){
        BiMap<Integer, String> empIDNameMap = HashBiMap.create();

        empIDNameMap.put(new Integer(101), "Mahesh");
        empIDNameMap.put(new Integer(102), "Sohan");
        empIDNameMap.put(new Integer(103), "Ramesh");

        System.out.println("size: "+empIDNameMap.size());
        // key value 反转
        // 普通 map 通过 key 查值，，bitmap 通过value 查key
        BiMap<String, Integer> inverse = empIDNameMap.inverse();
        System.out.println(inverse.get("Sohan"));
        System.out.println(inverse.containsKey("Sohan"));
        System.out.println(inverse.containsValue(new Integer(101)));

        //正常拿值
        System.out.println(empIDNameMap.get(new Integer(101)));
        System.out.println(empIDNameMap.containsKey(new Integer(101)));
    }


}
